////////////////////////////////////////////////////////////////////////////
//
//  CryEngine Source File.
//  Copyright (C), Crytek, 1999-2010.
// -------------------------------------------------------------------------
//  File name:	AssetTextureItem.h
//  Version:	v1.00
//  Created:	15/04/2009 by Paulo Zaffari
//  Description:	Header file for the class implementing IAssetDisplayItem
//								interface. It declares the headers of the actual used 
//								functions
// -------------------------------------------------------------------------  
//  History:
//		15/04/2009	11:00 - Paulo Zaffari - created
//		12/03/2010	17:30 - Nicusor Nedelcu - refactored
//		10/05/2010	13:49 - Nicusor Nedelcu - stripped common code to AssetBrowserCommon.h/cpp
//
//////////////////////////////////////////////////////////////////////////// 

#ifndef __AssetTextureItem_h__
#define __AssetTextureItem_h__
#pragma once

#include "Asset Browser/AssetBrowserCommon.h"
#include "AssetBrowserPreviewTextureDlg.h"
#include "Util/GdiUtil.h"

class ITexture;

class CAssetTextureItem: public CAssetDisplay
{
	public:

		friend class CAssetBrowserPreviewTextureDlg;

		enum EAssetTextureDrawingOption
		{
			eAssetTextureDrawing_RGBA = 0,
			eAssetTextureDrawing_Alpha,
			eAssetTextureDrawing_RGB,
		};

		CAssetTextureItem();
		~CAssetTextureItem();

		bool										GetAssetFieldValue( const char* pFieldName, void* pDest );
		bool										Cache();
		bool										CacheFieldsInfo();
		bool										UnCache();
		bool										UnCacheThumbnail();
		void										OnBeginPreview( const HWND hQuickPreviewWnd, const HDC hMemDC );
		void										OnEndPreview();
		void										InteractiveRender(	const HWND hRenderWindow, const CRect& rstViewport, int aMouseX, int aMouseY, int aMouseDeltaX,
																								int aMouseDeltaY, int aMouseWheelDelta, UINT aKeyFlags );
		void										OnInteractiveRenderKeyEvent( bool bKeyDown, UINT aChar, UINT aKeyFlags );
		bool										Render( const HWND hRenderWindow, const CRect& rstViewport, bool bCacheThumbnail = false );
		bool										DrawThumbImage( const HDC hDC, const CRect& rRect );
		bool										SaveReportImage( const char *filePath ) const;
		bool										SaveReportText( const char *filePath ) const;
		void										CacheFieldsInfoForLoadedTex( const ITexture *pTexture );
		CDialog*								GetCustomPreviewPanel( CWnd* pParentWnd );
		void										ToXML(XmlNodeRef& node) const;
		void										FromXML(const XmlNodeRef& node);

		HRESULT STDMETHODCALLTYPE	QueryInterface( const IID &riid, void **ppvObj ); 
		ULONG STDMETHODCALLTYPE		AddRef();
		ULONG STDMETHODCALLTYPE		Release();

	protected:

		void												DrawTextOnReportImage( CAlphaBitmap &abm ) const;
		void												PreviewCenterAndScaleToFit( const CRect& rViewport );

		CString											m_strSurfaceTypeString;
		bool												m_bHasAlphaChannel, m_bIsCubemap;
		UINT												m_nTextureWidth, m_nTextureHeight, m_nMips;
		ETEX_Format									m_format;
		CAlphaBitmap								m_oCachedThumbBmp, m_oPreviewBmp, m_oPreviewBmpAlpha, m_oPreviewBmpRGB;
		EAssetTextureDrawingOption	m_previewDrawingMode;
		static CAssetBrowserPreviewTextureDlg s_texturePreviewDlg;
		//! current rendering zoom ( 0.0f .. 1.0f [100%] )
		float												m_previewRenderZoom;
		CPoint											m_previewOffset;
		CSize												m_previewSize;
		COLORREF										m_previewBackColor;
		bool												m_bPreviewSmooth;
		int													m_previewMipLevel;
};

#endif //__AssetTextureItem_h__
